package com.bawei.module_launcher.me

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bawei.library_base.utils.GlobalThreadPools
import com.bawei.library_common.utils.CacheDataManager
import com.bawei.module_launcher.R
import com.bawei.module_launcher.databinding.LauncherFragmentMineBinding
import com.blankj.utilcode.util.SPUtils


class MeFragment : Fragment() {

    private val v : LauncherFragmentMineBinding by lazy { LauncherFragmentMineBinding.inflate(LayoutInflater.from(requireContext())) }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        v.userPage.backImg.visibility = View.GONE
        v.userPage.moreImg.setImageResource(com.bawei.library_base.R.drawable.icon644)
        v.userPage.moreImg.setOnClickListener {  }
        v.userPage.titleTv.text = "用户"
        v.userNameTv.text = "Root"
        v.userIdentityTv.text = "管理员"
        //获得缓存
        val totalCacheSize = CacheDataManager.getTotalCacheSize(context)
        v.userClearTv.text = "共有 $totalCacheSize 缓存可被清理"
        //退出登陆
        v.userExitTv.setOnClickListener {
            SPUtils.getInstance().clear()
            activity?.finish()
        }
        //清理缓存：线程池 耗时操作
        v.userClearTv.setOnClickListener {
            GlobalThreadPools.getInstance().execute {
                CacheDataManager.clearAllCache(context)
            }
        }
        return v.root
    }

}